package com.lhy.wcss.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhy.wcss.common.utls.SessionUtils;
import com.lhy.wcss.model.domain.WhitelistSetting;
import com.lhy.wcss.model.dto.ApplicationDTO;
import com.lhy.wcss.model.dto.DeleteDTO;
import com.lhy.wcss.model.dto.PageDTO;
import com.lhy.wcss.model.dto.ProductDTO;
import com.lhy.wcss.model.vo.ApplicationVO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lhy.wcss.common.JsonResponse;
import com.lhy.wcss.service.ApplicationService;
import com.lhy.wcss.model.domain.Application;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Controller
@RequestMapping("/application")
public class ApplicationController {

    private final Logger logger = LoggerFactory.getLogger(ApplicationController.class);

    @Autowired
    private ApplicationService applicationService;

    @PostMapping("/applicationSave")
    @ResponseBody
    public JsonResponse save(Application application) {
        applicationService.mySave(application);
        return JsonResponse.success(true);

    }

    /*待我审核*/
    @GetMapping("/waitAuditList")
    @ResponseBody
    public JsonResponse list(PageDTO pageDTO, Application application) {
        Page<Application> page = applicationService.waitAuditList(pageDTO, application);
        return JsonResponse.success(page);
    }

    /*审核*/
    @PostMapping("/audit")
    @ResponseBody
    public JsonResponse audit(Application application) {
        applicationService.audit(application);
        return JsonResponse.success(true);
    }

    /*批量审核*/
    @PostMapping("/audits")
    @ResponseBody
    public JsonResponse audits(@RequestBody ApplicationDTO applicationDTO) {
        applicationService.audits(applicationDTO);
        return JsonResponse.success(true);
    }

    /*移除表项*/
    @GetMapping("removeById")
    @ResponseBody
    public JsonResponse removeById(Long id) {
        boolean b = applicationService.removeById(id);
        return JsonResponse.success(b);
    }

    @PostMapping("/removeById")
    @ResponseBody
    public JsonResponse removeById(@RequestBody DeleteDTO deleteDTO) {
        boolean b = applicationService.removeById(deleteDTO.getId());
        return JsonResponse.success(b);
    }

    @PostMapping("/save")
    @ResponseBody
    public JsonResponse save(@RequestBody ApplicationDTO applicationDTO){
        applicationService.mySaves(applicationDTO);
        return JsonResponse.success(true);
    }

    /*
//     * 数据修改
//     * 状态修改
//     * 编辑
//     * */

//   @GetMapping("/getBySn")
//  @ResponseBody
//  public JsonResponse getBySn(String sn) {
//       System.out.println(sn);
//       Application application = applicationService.getBySn(sn);
//       return JsonResponse.success(application);
//   }


//   /*导出*/
//   @GetMapping("/export")
//   @ResponseBody
//    public void export(HttpServletResponse response){
//        applicationService.export(response);
//   }
//
//   /*导入模板*/
//   @GetMapping("/exportTemp")
//  public void exportTemp(HttpServletResponse response){
//       applicationService.exportTemp(response);
//   }
//
//   /*文件上传导入*/
//   @PostMapping("/inputUserByFile")
//   @ResponseBody
//    public JsonResponse inputUserByFile(MultipartFile file){
//       Map<String,Object> msg=applicationService.inputUser(file);
//
//       return JsonResponse.success(msg);
//  }
    /*插入*/
    @RequestMapping("/insert")
    @ResponseBody
    public JsonResponse insertUser(Application application) {
        System.out.println(application.toString());
        boolean b = applicationService.save(application);
        return JsonResponse.success(b);
    }


    /*申请列表*/
    @GetMapping("/sqList")
    @ResponseBody
    public JsonResponse sqList(PageDTO pageDTO, Application application) {
        Page<Application> page = applicationService.pageList(pageDTO, application);
        return JsonResponse.success(page);
    }
}

